/**
 * Copyright 2016-2018 mobaas.com
 */
package com.mobaas.devops.node.docker;

import java.util.Base64;

/**
 * 
 * @author billy zhang
 *
 */
public class RegistryAuth {

	private String serverAddress;
	private String username;
	private String password;
	private String email;
	
	public String getServerAddress() {
		return serverAddress;
	}
	public void setServerAddress(String serverAddress) {
		this.serverAddress = serverAddress;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String toJsonForAuth() {
		
		String auth = String.format("{ \"username\":\"%s\", \"password\":\"%s\", \"email\":\"%s\", \"serveraddress\":\"%s\" }"
				, username, password, email, serverAddress);
		return Base64.getEncoder().encodeToString(auth.getBytes());
	}
	
	public String toJsonForConfig() {
		
		String config = String.format("{ \"%s\": { \"ussername\":\"%s\", \"password\":\"%s\" } }"
				, serverAddress, username, password);
		return Base64.getEncoder().encodeToString(config.getBytes());
	}
	
	public String toString() {
		
		return String.format("RegistryHost: %s, username: %s, password: %s, email: %s", 
				serverAddress, username, password, email);
	}
}
